package com.oa.srms.apps.actions;

import java.text.SimpleDateFormat;

@SuppressWarnings("serial")
public class DBAction extends BasicAction {

	private String filename;
	
	public String toDBManager(){
		return SUCCESS;
	}
	
	public String backup() throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		try {
			Runtime.getRuntime().exec("cmd  /c  mysqldump -uroot -proot srms > d:/dumps/" + sdf.format(new java.util.Date())+ ".sql");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public void backupAuto() throws Exception{
		System.out.println("Backup is starting");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String dateStr = sdf.format(new java.util.Date());
		try {
			Runtime.getRuntime().exec("cmd  /c  mysqldump -uroot -proot srms > d:/dumps/" + dateStr + ".sql");
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("Backup is end. Date:["+dateStr+"]");
	}
	
	public String load() throws Exception{
		try {
			Runtime.getRuntime().exec("cmd  /c  mysql -uroot -proot srms < d:/dumps/" + filename + ".sql");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}
	
}
